//
//  SwiftMainListCell.swift
//  testTableView
//
//  Created by LYJ on 2019/9/20.
//  Copyright © 2019 LYJ. All rights reserved.
//

import UIKit
import SnapKit



class SwiftMainListCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.addSubview(nameLabel)
        contentView.addSubview(introduceLabel)
        contentView.addSubview(headImv)
        swiftViewsLayout()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func configureCellWithData(dataDic: NSDictionary) {
        nameLabel.text = dataDic["userName"] as? String
        introduceLabel.text = dataDic["introduce"] as? String
    }
    
    //MARK: layout
    func swiftViewsLayout() {
        headImv.snp.makeConstraints { (make) in
            make.left.equalTo(self.contentView).offset(WIDTH_PRO(X: 10))
            make.width.height.equalTo(WIDTH_PRO(X: 33))
            make.top.equalTo(self.contentView).offset(WIDTH_PRO(X: 5))
        }
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.contentView)
            make.height.equalTo(WIDTH_PRO(X: 25))
            make.left.equalTo(self.headImv.snp_right).offset(WIDTH_PRO(X: 5))
            make.right.equalTo(self.contentView).offset(WIDTH_PRO(X: -10))
        }
        introduceLabel.snp.makeConstraints { (make) in
            make.top.equalTo(self.nameLabel.snp_bottom)
            make.bottom.equalTo(self.contentView).offset(HEIGHT_PRO(X: -5))
            make.left.right.equalTo(self.nameLabel)
        }
    }
    
    //MARK: lazy
    lazy var nameLabel: UILabel = {
        let nameLabel = UILabel.init()
        nameLabel.font = UIFont.systemFont(ofSize: 17)
        return nameLabel
    }()
    
    lazy var introduceLabel: UILabel = {
        let introduceLabel = UILabel.init()
        introduceLabel.font = UIFont.systemFont(ofSize: 14)
        introduceLabel.numberOfLines = 0
        introduceLabel.textAlignment = .left
        introduceLabel.lineBreakMode = NSLineBreakMode.byWordWrapping
        return introduceLabel
    }()
    
    lazy var headImv: UIImageView = {
        let headImv = UIImageView.init()
        headImv.layer.masksToBounds = true
        headImv.layer.cornerRadius = 33/2.0
        headImv.contentMode = UIView.ContentMode.scaleAspectFill
        headImv.image = UIImage(named: "avatar_placeHolder")
        return headImv
    }()
}
